import Toast from '../../miniprogram_npm/vant-weapp/toast/toast';

Page({
  data: {
    username:'',
    password:''
  },
  onLoad: function () {
    
  },
  bindUser(e){
    this.setData({
      username:e.detail.value
    })
  },
  bindPass(e){
    // console.log(e);
    this.setData({
      password:e.detail.value
    })
  },

  goHome(){
    // setTimeout(()=>{wx.switchTab({url: '../home/index'})},1000);
    // return;

    wx.showLoading({
      title: '登录中...',
    })
    const th = this.data;
    wx.request({
      url: 'https://www.bchzh.xin/hzmobilework/app/login/loginApp',
      data: {
        username: th.username,
        password: th.password
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        wx.hideLoading()
        if(res.data.code == '1'){
          // wx.showToast({title:res.data.message})
          wx.setStorage({
            key: 'userInfo',
            data: res.data.data,
          })
          Toast.success(res.data.message);
          setTimeout(()=>{wx.switchTab({url: '../home/index'})},1000)
          
        }else{
          wx.showToast({ title: res.data.message, icon: 'none', mask:true})
          // Toast.fail(res.data.message)
        }
      },
      fail: function() {
        // fail
        console.log(res);
      },
      complete: function(res) {
        // complete
        
      }
    })



    //wx.switchTab({url:'../home/index'})
  }
})
